﻿<UserControl x:Class="BaMusaSoft.RPS.View.ContractView" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" 
             xmlns:wpfExtended="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
             xmlns:p="clr-namespace:BaMusaSoft.RPS.View.Properties"
             mc:Ignorable="d" d:DesignHeight="650" d:DesignWidth="500" 
             FlowDirection="RightToLeft"
             Loaded="ViewLoaded" Unloaded="ViewUnloaded">
             
    <UserControl.Resources>
        <DataTemplate x:Key="AllContracts">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Image Grid.Column="0" Grid.RowSpan="2" Source="{StaticResource ResourceKey=ContractImage}"
                       Width="80" Height="80"/>
                <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=Property.Description}"/>
                <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Path=Customer.Name}"/>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="SearchTextBox">
            <Grid FocusManager.FocusedElement="{Binding ElementName=txtPropertySearch}"> 
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox Grid.Column="0" x:Name="txtPropertySearch" Text="{Binding PropertySearchField}" Height="30"
                         ToolTip="{x:Static p:Resources.ContractView_SearchToolTip}"/>
                <Button Grid.Column="1" Content="{StaticResource FindImage}" Command="{Binding SearchCommand}"/>
               
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot"   >
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.541*" />
            <ColumnDefinition Width="0.541*" />
            <ColumnDefinition Width="0.541*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <StackPanel Grid.ColumnSpan="3" Orientation="Horizontal">
                <Button Content="Save" Command="{Binding SaveCommand, Mode=OneWay}" Margin="3"/>
                <Button Content="Print" Command="{Binding PrintCommand, Mode=OneWay}" Margin="3"/>

        </StackPanel>
        <Border Grid.Column="0" Grid.Row="1" Grid.RowSpan="4" Margin="0,20,10,0">
            <DockPanel>
                
                <ContentControl DockPanel.Dock="Top" Content="{Binding}" ContentTemplate="{StaticResource SearchTextBox}"
                                Margin="0,0,0,5"/>
                <ListBox ItemsSource="{Binding Contracts}" IsSynchronizedWithCurrentItem="True"
                         ItemTemplate="{StaticResource AllContracts}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <VirtualizingStackPanel/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <i:Interaction.Triggers>
                        <i:EventTrigger EventName="SelectionChanged">
                            <ei:CallMethodAction TargetObject="{Binding}" MethodName="SelectedContractChanged"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>

                </ListBox>
            </DockPanel>
        </Border>
        <GroupBox Grid.Row="2" Header="بيانات التسجيل" Margin="3,20,45,3" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="اليوم"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="1" Grid.Column="0" Text="التاريخ الهجري"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="التاريخ الميلادي"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBox Grid.Row="0" Grid.Column="1" x:Name="ttt" Margin="4,10,5,4" Height="30" Text="{Binding Path=SignDay, UpdateSourceTrigger=PropertyChanged}" />
                <wpfExtended:MaskedTextBox  Grid.Row="1" Grid.Column="1" Margin="4,10,5,4" Height="30" IncludeLiterals="False" IncludePrompt="False"
                                            Value="{Binding Path=SignHijriDate, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DateConverter}}"
                                            Mask="##/ ## /####"/>
                <wpfExtended:MaskedTextBox  Grid.Row="2" Grid.Column="1" Margin="4,10,5,4" Height="30" IncludeLiterals="False" IncludePrompt="False"
                                            Value="{Binding Path=SignGregDate, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource DateConverter}}"
                                            Mask="##/ ## /####"/>
            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="3" Header="بيانات المستأجر" Margin="3,30,45,3" Grid.Column="1">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="الإسم"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="1" Grid.Column="0" Text="رقم الهوية"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="تايخها"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="3" Grid.Column="0" Text="مصدرها"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="4" Grid.Column="0" Text="العنوان"  Margin="0,10,4,4" TextAlignment="Left" VerticalAlignment="Center" />
                <TextBox Grid.Row="0" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding CustomerName, Mode=OneWay}" />
                <TextBox Grid.Row="1" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding CustomerIdNumber, Mode=OneWay}" />
                <wpfExtended:MaskedTextBox  Grid.Row="2" Grid.Column="1" Margin="4,10,5,4" Height="30" IncludeLiterals="False" IncludePrompt="False"
                                            Value="{Binding Path=CustomerIdDate, Mode=OneWay, Converter={StaticResource DateConverter}}"
                                            Mask="##/ ## /####"/>
                <TextBox Grid.Row="3" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding CustomerIdIssue, Mode=OneWay}" />
                <TextBox Grid.Row="4" Grid.Column="1" Margin="4,10,5,4" Text="{Binding CustomerAddress, Mode=OneWay}"/>

            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="2" Grid.Column="2" Header="بيانات العقار" Margin="57,20,3,3">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="نوع المؤجر"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="1" Grid.Column="0" Text="رقم العين"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="الموقع"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="3" Grid.Column="0" Text="الحي" Margin="0,10,4,4" TextAlignment="Left" />
                <TextBox Grid.Row="0" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=PropertyType, Mode=OneWay}" />
                <TextBox Grid.Row="1" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=PropertyNumber, Mode=OneWay}"/>
                <TextBox Grid.Row="2" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=PropertyLocation, Mode=OneWay}"/>
                <TextBox Grid.Row="3" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=PropertyDistrict, UpdateSourceTrigger=PropertyChanged}"/>

            </Grid>
        </GroupBox>
        <GroupBox Grid.Row="3" Grid.Column="2" Header="بيانات العقد" Margin="57,30,3,3">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="غرض الإيجار"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="1" Grid.Column="0" Text="مدة الإيجار"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="2" Grid.Column="0" Text="بداية العقد"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="3" Grid.Column="0" Text="نهاية العقد"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="4" Grid.Column="0" Text="المربوط" Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="5" Grid.Column="0" Text="التأمين"  Margin="0,10,4,4" TextAlignment="Left" />
                <TextBlock Grid.Row="6" Grid.Column="0" Text="الصيانة"  Margin="0,10,4,4" TextAlignment="Left" />
                <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" Margin="4,10,5,4">
                    <ComboBox  Height="30" ItemsSource="{Binding Activities}" MinWidth="150" 
                               DisplayMemberPath="Description" 
                               SelectedValue="{Binding Path=Activity}"/>
                    <Button Content="Add..." Command="{Binding AddActivityCommand}"/>
                </StackPanel>

                <TextBox Grid.Row="1" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=ContractPeriod, Mode=OneWay}"/>
                <wpfExtended:MaskedTextBox  Grid.Row="2" Grid.Column="1" Margin="4,10,5,4" Height="30"  IncludeLiterals="False" IncludePrompt="False"
                                            Value="{Binding Path=StartDate, Mode=OneWay, Converter={StaticResource DateConverter}}"
                                            Mask="##/ ## /####"/>
                <wpfExtended:MaskedTextBox  Grid.Row="3" Grid.Column="1" Margin="4,10,5,4" Height="30"  IncludeLiterals="False" IncludePrompt="False"
                                            Value="{Binding Path=EndDate, Mode=OneWay, Converter={StaticResource DateConverter}}"
                                            Mask="##/ ## /####"/>
                <TextBox Grid.Row="4" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=AgreedRent, Mode=OneWay}"/>
                <TextBox Grid.Row="5" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=AgreedDeposit, Mode=OneWay}"/>
                <TextBox Grid.Row="6" Grid.Column="1" Margin="4,10,5,4" Height="30" Text="{Binding Path=AgreedMaintenance, Mode=OneWay}"/>
            </Grid>
        </GroupBox>
    </Grid>
</UserControl>
